package top.zimang.loveforwords.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

import top.zimang.loveforwords.Model.Acceptation;
import top.zimang.loveforwords.Model.ExampleSentence;
import top.zimang.loveforwords.R;
import top.zimang.loveforwords.ViewHolder.AcceptationHolder;
import top.zimang.loveforwords.ViewHolder.ExmHolder;

public class ExampleSentenceAdapter extends ArrayAdapter<ExampleSentence> {
    private int resId;
    private ExmHolder exmHolder;
    public ExampleSentenceAdapter(@NonNull Context context, int resource, @NonNull List<ExampleSentence> objects) {
        super(context, resource, objects);
        resId=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ExampleSentence exampleSentence=(ExampleSentence) getItem(position);
        View view;
        if (convertView==null){
            view= LayoutInflater.from(getContext()).inflate(resId,parent,false);
            this.exmHolder=new ExmHolder();
            this.exmHolder.setOrig((TextView) view.findViewById(R.id.exa));
            this.exmHolder.setTrans((TextView) view.findViewById(R.id.exa_trans));
            view.setTag(exmHolder);
        }else {
            view=convertView;
            exmHolder=(ExmHolder) view.getTag();
        }
        exmHolder.getOrig().setText(exampleSentence.getExa());
        exmHolder.getTrans().setText(exampleSentence.getExaTrans());
        return view;

    }
}
